package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {

        Class cls = Class.forName("reflect.Person");
        Method method = cls.getMethod("say", String.class, int.class);

        String name = method.getName();
        System.out.println("方法名：" + name);

        Class[] paramTypes = method.getParameterTypes();
        for (Class paramType : paramTypes) {
            System.out.println("参数类型：" + paramType.getName());
        }

        int count = method.getParameterCount();
        System.out.println("参数个数有：" + count);

        Class returnType = method.getReturnType();
        System.out.println("返回值类型：" + returnType.getName());

        //获取方法的访问修饰符
        int modifiers = method.getModifiers();
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("访问修饰符：public");
                break;
            case Modifier.PROTECTED:
                System.out.println("访问修饰符：protected");
                break;
            case Modifier.PRIVATE:
                System.out.println("访问修饰符：private");
                break;
            case Modifier.ABSTRACT:
                System.out.println("访问修饰符：abstract");
                break;
            default:
                System.out.println("方法为默认");
                break;
        }













    }
}
